def codeFormating(code):
    """
    编码输入检查
    """
    
    code = str(code)
    
    if "'" in code:
        code = code.split("'")[0]
    elif "." in code:
        code = code.split(".")[0]
    
    print(code, type(code))
    return code


def dateFormating(date, mode="L/S"):
    """
    日期格式检查
    mode = S long to shot | L shot to long 以输出的为准
    只输出日期,所有带有时间的将被过滤
    """

    def splitjoin(date):
        if "-" in date:
            date = "".join(date.split("-"))
        elif "/" in date:
            date = "".join(date.split("/"))
        return date


    date = str(date)

    if mode == "L":
        if len(date) == 8 and ":" not in date:
            date = "{}-{}-{}".format(date[:4], date[4:6], date[6:])
        elif len(date) > 8 and (" " in date or ":" in date):
            date = date.split(" ")[0]
            if "/" in date:
                date = date.split("/")
                if date[-1] > 1:
                    d = int(date[-1]) - 1
                else:
                    d = 1
                    date = "{}-{}-{}".format(date[0], date[1], d)
            # elif "-" in date:
            #     date = date.split("-")
            #     if date[-1] > 1:
            #         d = int(date[-1]) - 1
            #     else:
            #         d = 1
            #         date = "{}-{}-{}".format(date[0], date[1], d)
        elif len(date) < 8:
            print("error --> datetype")
            exit()
    elif mode == "S":
        if len(date) < 11:
            date = splitjoin(date)
        elif len(date) > 11 and ":" in date:
            date = date.split(" ")[0]
            date = splitjoin(date)

    return date
